using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    public class Or : Instruction
    {
        public override int CycleCount
        {
            get { return 1; }
        }

        public Or()
            : base("or")
        {
        }

        /// <summary>
        /// The contents of register rA are ORed with the contents of register rB; the result is placed
        /// into register rD.
        /// </summary>
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            uint sa = MicroblazeComponent.ReadRegister(SourceRegisterA);
            uint sb = MicroblazeComponent.ReadRegister(SourceRegisterB);

            // compute and save
            MicroblazeComponent.WriteRegister(DestinationRegister, sa | sb, Address);
        }

        public override string ToString()
        {
            return String.Format("or r{0}, r{1}, r{2}",
                DestinationRegister,
                SourceRegisterA,
                SourceRegisterB
            );
        }
    }
}
